// 权限认证-登录拦截
import router from './router'
import store from './store'
// 引入进度条
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style

import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/404']
// 路由前置守卫
router.beforeEach((to, from, next) => {
  NProgress.start()
  document.title = getPageTitle(to.meta.title)
  // 有token
  if (store.getters.token) {
    next()
  } else {
    // 如果是白名单
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})

// 后置守卫
router.afterEach(() => {
  NProgress.done()
})
